<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>2019-nCoV</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <link rel="stylesheet" href="./css/my-css.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="./">首页</a>
            <a>
              <cite>实时数据</cite>
            </a>
            <a>
              <cite>国外实时</cite>
            </a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-body ">
							<table id="tableInfo" lay-filter="tableInfo-filter"></table>
                        </div>
					</div>
                </div>
            </div>
        </div> 
    </body>
    
    <script type="text/html" id="tableToolBar">
  		<div class="layui-btn-container">
    		<a class="layui-btn layui-btn-xs" th:href="'./../admin/realTimeDataAdd?type='+${type}">添加</a>
  		</div>
	</script>
	<script type="text/html" id="tableBar">
  		<a class="layui-btn layui-bg-blue layui-btn-xs" th:href="'./../admin/realTimeDataDetail?datasCode={{d.code}}&type='+${type}">详情</a>
  		<a class="layui-btn layui-bg-orange layui-btn-xs" th:href="'./../admin/realTimeDataUpdate?datasCode={{d.code}}&type='+${type}">更新</a>
  		<a class="layui-btn layui-bg-red layui-btn-xs" lay-event="del">删除</a>
	</script>
						
    <script th:inline="none">
      layui.use(['laydate','form', 'table'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;
        
        table.render({
	          elem: '#tableInfo'
	          ,url: './../datas/list?type=FOREIGN'
	          ,toolbar: '#tableToolBar'
	          ,page: true
	          ,cols: [[
	            {field: 'code', title: '编号', width:120, sort: true, fixed: 'left'}
	            ,{field: 'confirmed', title: '确诊', width:180}
	            ,{field: 'suspected', title: '疑似', width:180} 
	            ,{field: 'healed', title: '治愈', width:180, sort: true}
	            ,{field: 'dead', title: '死亡', width:180, sort: true}
	            ,{field: 'gmtCreated', title: '创建时间', width: 180 , sort: true}
	            ,{field: 'gmtModified', title: '更新时间', width: 180, sort: true}
	            ,{fixed: 'right', title:'操作', toolbar: '#tableBar', width: 190}
	          ]]
      	});

      	//监听行工具事件
        table.on('tool(tableInfo-filter)', function(obj){
        	var data = obj.data;
          
        	if(obj.event === 'del') {
        		layer.confirm('真的删除行么', function(index){
        			postAjax('./../datas/delete', {'datasCode': data.code});
        			reloadTable();
           		});
         	}
        });
      	
      	var reloadTable = function() {
      		table.reload('tableInfo', {
      			where: { //设定异步数据接口的额外参数，任意设
      				//aaaaaa: 'xxx'
      			    //,bbb: 'yyy'
      			    // …
      			  }
      			  ,page: {
  			      	curr: 1 //重新从第 1 页开始
  			  	  }
      		});
      	}
      	
      });
      
	var postAjax = function(postUrl, postData) {
		var index =layer.load(2, { shade: [0.1,'#fff'] });
			$.ajax({
		    	url:postUrl,
		      	type:'post',
		      	dataType:'json',
		      	contentType:"application/json",
		      	async:true,
		      	cache:false,
		      	data:JSON.stringify(postData),
		      	success:function(data) {
		      		if(data.code == 0) {
		      			layer.close(index);
		      			layer.msg(data.msg, {icon: 1});
			      	} else {
			      		layer.close(index);
			        	layer.msg(data.msg, {icon: 2});
			      	}
				},
		  		error:function(data) {
		      		layer.close(index);
		      		layer.msg('网络异常', {icon: 7});
				}
			});
	}
    </script>
</html>